--
-- Author: mengjie
-- Date: 2016-04-13 20:34:04
--
BaseBlockTYPE={
	STARTING=1, -- 起跑线
	FIRST = 2, --第一步
	NORMAL = 3, -- 正常
	ENDLINE = 4, --结束
}
local BaseBlock = import(".BaseBlock")
local LineBlock = class("LineBlock",function()
	return display.newNode()
end)
function LineBlock:ctor(lineType)
	self.blocks={}
	self.selectIndex = 0
	local block
	self.selectIndex = math.random(1,CELL_WIDTH_COUNT)
	for i=1,CELL_WIDTH_COUNT do
		if lineType == BaseBlockTYPE.STARTING then
			block = BaseBlock.new(1)
		elseif lineType == BaseBlockTYPE.ENDLINE then
			block = BaseBlock.new(2)
		elseif self.selectIndex == i then
			block = BaseBlock.new(6)
		else
			block = BaseBlock.new(7)
		end
		block:setPosition((i-1)*CELL_WIDTH+i, 0)
		self:addChild(block)
		self.blocks[#self.blocks+1]=block
	end
	if lineType == BaseBlockTYPE.FIRST then
		self.label = display.newTTFLabel({
		    text = "开始",
		    size = 38,
		    align = cc.TEXT_ALIGNMENT_CENTER
		})
		self.label:setPosition(self.selectIndex*CELL_WIDTH-CELL_WIDTH/2, CELL_HEIGHT/2)
		self:addChild(self.label)
	end
end
function LineBlock:clickCell(index)
	if self.label then
		self.label:removeSelf()
		self.label = nil
	end
	local block = self.blocks[index]
	if self.selectIndex == index then
		block:setBgType(3)
		return true
	else
		block:setBgType(4)
		return false
	end
 	
end
function LineBlock:changeType(lineType)
	self.selectIndex = math.random(1,CELL_WIDTH_COUNT)
	for i,block in ipairs(self.blocks) do
		if lineType == BaseBlockTYPE.STARTING then
			block:setBgType(1)
		elseif lineType == BaseBlockTYPE.ENDLINE then
			block:setBgType(2)
		elseif self.selectIndex == i then
			block:setBgType(6)
		else
			block:setBgType(7)
		end
	end
	
end
return LineBlock